package org.kealinghornets.dl.jh.average;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity {

    public void OnActivateClick (View view){

        EditText tasty = (EditText) findViewById(R.id.editText_number1);
        EditText toasty = (EditText) findViewById(R.id.editText_number2);
        String input1 = tasty.getText().toString();
        String input2 = toasty.getText().toString();
        Toast.makeText(getApplicationContext(),input1,Toast.LENGTH_LONG).show();
        Toast.makeText (getApplicationContext(),input2,Toast.LENGTH_LONG).show();

        double frozen;

        if(input1 == null || input1.length() == 0){
            frozen = 0.0;
        } else {
          frozen = Double.parseDouble(tasty.getText().toString());
        }

        double frosting;


            if(input2 == null || input2.length() == 0){
                frosting = 0.0;
            } else {
                frosting = Double.parseDouble(toasty.getText().toString());
            }

        double average = (frosting +frozen)/2;
        String variable = average + "";
        EditText asian = (EditText)findViewById(R.id.editText_answer);
        asian.setText(variable);

    }
    public void onCopyClick (View view){

        EditText asia = (EditText)findViewById(R.id.editText_answer);


        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("label", asia.getText().toString());
        clipboard.setPrimaryClip(clip);

        Toast.makeText(getApplicationContext(),"Copy you fools",Toast.LENGTH_LONG).show();



    }









    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}
